using System.Collections.Generic;
using Dimebrain.TweetSharp.Model;

namespace twimilar.DomainModel
{
	public class User
	{
		private readonly List<string> _messages = new List<string>();

		public User(string screenName, string status)
		{
			TwitterUser = new TwitterUser()
											{
												ScreenName = screenName,
												Status = new TwitterStatus()
																	{
																		Text = status
																	}
											};
			Words = new Dictionary<string, int>();

			if (TwitterUser.Status != null)
				AddTweet(TwitterUser.Status.Text);
		}

		public User(TwitterUser user)
		{
			TwitterUser = user;
			Words = new Dictionary<string, int>();

			if (TwitterUser.Status != null)
				AddTweet(TwitterUser.Status.Text);
		}

		public TwitterUser TwitterUser { get; private set; }

		public Dictionary<string, int> Words { get; private set; }

		public void AddTweet(string message)
		{
			if (_messages.Contains(message) || message.Contains("RT"))
				return;

			_messages.Add(message);

			var words = message.GetWords();
			foreach (string word in words)
			{
				if (Words.ContainsKey(word))
					Words[word] += 1;
				else
					Words[word] = 1;
			}
		}
	}
}